package com.share.alibaba.agetway.model;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

import java.util.Date;

/**
 * @JSONField(ordinal = 1) alibaba的json设置排序
 * @JsonPropertyOrder(alphabetic = false)  是jackJSON的排序,使用了java的方式,性能比较低
 */
@Data
@JsonPropertyOrder(alphabetic = false)
public class AccessLog {

    private String uri;

    private String request;

    private String response;

    private String ip;

    private String method;

    private long startTime;

    private long endTime;

    private long costTime;

    private Date createTime = new Date();

    private static ObjectMapper objectMapper=new ObjectMapper();

    public String toJSONString() {
        try {
            return objectMapper.writeValueAsString(this);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
